import 'reflect-metadata/Reflect.js';
import { fancyTimeFormat } from 'src/utils/common';
import { Type } from 'class-transformer';
import Audio from './Audio';
import Base from './Base';
export default class Video extends Base {
  public title = '';
  public description = '';
  public url = '';
  public mimeType = VideoMimeType.MP4;
  public duration = 0;
  public languages: string[] = [];
  public viewCount = 0;
  public complimentsCount = 0;
  public audioCount = 0;
  public likeCount = 0;
  public dislikeCount = 0;
  public isLiked = false;
  public isDisliked = false;
  public categoryId = '';
  public categoryName = '';
  public coverImage?: string;
  public creatorName = '';
  public creatorId = '';
  public creatorAvatar?: string;
  public creatorCategory = '';
  public creatorFollowersCount = 0;
  public channelId = '';
  public tags: string[] = [];
  public status: VideoStatus = VideoStatus.UNKNOWN;
  public compliments: VideoCompliments[] = [];
  public isBookmarked = false;
  public isPinned = false;
  @Type(() => Audio)
  public audios: Audio[] = [];
  @Type(() => Audio)
  public currentAudio?: Audio;
  @Type(() => Audio)
  public filteredAudio?: Audio[];
  public visability = 0;
  constructor(id: string, title = 'Title', creator = 'Author') {
    super();
    this.id = id;
    this.title = title;
    this.categoryName = creator;
  }
  public get durationLabel(): string {
    return fancyTimeFormat(this.duration);
  }
  public get likePercent(): number {
    const total = this.likeCount + this.dislikeCount;
    return Math.round((this.likeCount / total) * 100);
  }
}

export enum VideoStatus {
  UNKNOWN = 0,
  NORMAL = 1,
  UPLOADING = 2,
  VERIFING = 3,
  DISALBED = 4,
  PRIVATE = 5,
  DRAFT = 6,
  UNPUBLISHED = 7,
}
export enum VideoMimeType {
  MP4 = 'video/mp4',
  WEBM = 'video/webm',
  OGG = 'video/ogg',
  FLV = 'video/x-flv',
  TS = 'video/mp2t',
  M4V = 'video/m4v',
}

export class VideoTag {
  public id = '';
  public label = '';
  public color = '';
  public icon = '';
}
export class VideoCompliments {
  public id = '';
  public source = '';
  public isAnimation = false;
  public label = '';
  public count = 0;
  public isOn = false;
}
export class VideoUploadInfo {
  public title = '';
  public description = '';
  public langCode = '';
  public thumbnailFile = '';
  public medium = '';
  public software = '';
  public topics: string[] = [];
  public tags: string[] = [];
  public visability = true;
}
